/*****************************************************************************
 * File of local video playing interface
 * The maximal supported formats according to feature of different platform are list below:
 *   +-----------------------------------------------------------------------------------------------------+
 *   |					   	| MT6225				|	MT6226,MT6228,MT6238		|	MT6235
 *   +-----------------------------------------------------------------------------------------------------+
 *   | File format     		| AVI				|	3GP,MP4						|	3GP,MP4/AVI
 *   +-----------------------------------------------------------------------------------------------------+
 *   | Video encode format  |Motion JPEG			|	MP4,3GP 						|	MP4,3GP/AVI 	
 *   +-----------------------------------------------------------------------------------------------------+
 *   | Audio encode format  |PCM				|	AMR,AAC						|	AMR,AAC
 *   +-----------------------------------------------------------------------------------------------------+
 *
 *	Rule description:
 *	1. This playing interface support 2 layer at most currently. 
 *  The layer resource should be created and pass as parameters.
 *	Once the APP is switched into background, please stop video playing and release layer resources,
 *	and record current playing time that used for recovering when APP is switched into foreground.
 *	If not, the system would close the video and release the resources without recording andy infos.
 *	
 *	2. Video is prior to audio: when audio is playing, open a video would close the audio
 *  (except for bitstream audio, when bitstream audio is in use, open a video would return a failure).
 *	3. When video is open/play, and open/play again, a failure would be returned.
 *
 *
 ****************************************************************************/
#ifndef _VM_VIDEO_H
#define _VM_VIDEO_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vmsys.h"
#include "vmmm.h"




/**
 *	Success.
 */
#define VM_VIDEO_SUCCESS    (0)
/**
 *	Failed.
 */
#define VM_VIDEO_FAILED    (-1)


/**
 *	Data not enough.
 */
#define VM_VIDEO_PROGRESSIVE_FILE_NOT_ENOUGH   	-101




/**
 *	File open failed.
 */
#define VM_VIDEO_ERR_OPEN_FILE_FAILED           		-103

/**
 *	File size too large.
 */
#define VM_VIDEO_ERR_FILE_TOO_LARGE             		-104

/**
 *	Snapshot failed.
 */
#define VM_VIDEO_ERR_SNAPSHOT_FAILED            		-105

/**
 *	Play failed.
 */
#define VM_VIDEO_ERR_PLAY_FAILED                		-106



/**
 *	Snapshot failed because of the disk is full.
 */
#define VM_VIDEO_ERR_SNAPSHOT_DISK_FULL         	-107

/**
 *	Snapshot failed because of the write protection.
 */
#define VM_VIDEO_ERR_SNAPSHOT_WRITE_PROTECTION  -108

/**
 *	Invalid resolution.
 */
#define VM_VIDEO_ERR_INVALID_RESOULTION         	-109   

/**
 *	Unsupported format.
 */
#define VM_VIDEO_ERR_UNSUPPORTED_FORMAT         	-110

/**
 *	Memory is insufficient.
 */
#define VM_VIDEO_ERR_MEMORY_INSUFFICIENT        	-111

/**
 *	DRM is prohibited.
 */
#define VM_VIDEO_ERR_DRM_PROHIBITED             		-112     

/**
 *	DRM duration is used.
 */
#define VM_VIDEO_ERR_DRM_DURATION_USED          	-113

/**
 *	Frame rate is too high.
 */
#define VM_VIDEO_ERR_FRAMERATE_TOO_HIGH         	-114



/**
 *	Brightness darker than N4 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_N5              0	
/**
 *	Brightness darker than N3 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_N4              1    
/**
 *	Brightness darker than N2 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_N3              2	
/**
 *	Brightness darker than N1 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_N2              3	
/**
 *	Brightness darker than default by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_N1              4		
/**
 *	Default brightness.
 */
#define VM_VIDEO_BRIGHTNESS_0                5  
/**
 *	Brightness lighter than default by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_P1              6	
/**
 *	Brightness lighter than P1 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_P2              7	
/**
 *	Brightness lighter than P2 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_P3              8	
/**
 *	Brightness lighter than P3 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_P4              9	
/**
 *	Brightness lighter than P4 by 1 level.
 */
#define VM_VIDEO_BRIGHTNESS_P5              10	


/**
 *	Contrast lower than N4 by 1 level.
 */
#define VM_VIDEO_CONTRAST_N5                0	
/**
 *	Contrast lower than N3 by 1 level.
 */
#define VM_VIDEO_CONTRAST_N4                1	
/**
 *	Contrast lower than N2 by 1 level.
 */
#define VM_VIDEO_CONTRAST_N3                2	
/**
 *	Contrast lower than N1 by 1 level.
 */
#define VM_VIDEO_CONTRAST_N2                3	
/**
 *	Contrast lower than default by 1 level.
 */
#define VM_VIDEO_CONTRAST_N1                4	
/**
 *	Default contrast.
 */
#define VM_VIDEO_CONTRAST_0                 5	
/**
 *	Contrast higher than default by 1 level.
 */
#define VM_VIDEO_CONTRAST_P1                6	
/**
 *	Contrast higher than P1 by 1 level.
 */
#define VM_VIDEO_CONTRAST_P2                7	
/**
 *	Contrast higher than P2 by 1 level.
 */
#define VM_VIDEO_CONTRAST_P3                8	
/**
 *	Contrast higher than P3 by 1 level.
 */
#define VM_VIDEO_CONTRAST_P4                9	
/**
 *	Contrast higher than P4 by 1 level.
 */
#define VM_VIDEO_CONTRAST_P5                10	




/**
 *	Definition of A/V(Audio/Video) track in video.
 */
typedef enum
{
    VM_VIDEO_TRACK_NONE,   
    VM_VIDEO_TRACK_AV,     /* Video file with A/V track */
    VM_VIDEO_TRACK_A_ONLY, /* Video file with A track only */
    VM_VIDEO_TRACK_V_ONLY /* Video file with V track only */
} vm_video_track_enum;


/**
 *	Definition of buffer for video description info, count in UCS2, maximal 80 characters.
 */
#define VM_VIDEO_MAX_CONTENT_INFO_LEN   80


/**
 *	Struct of video info.
 */
typedef struct
{
    VMUINT16 width;                      /* Width  */
    VMUINT16 height;                     /* Height  */
    VMUINT32 total_frame_count;          /* Frame count  */
    VMUINT64 total_time_duration;        /* Time duration  */
    vm_video_track_enum track;     
    VMINT handle;              /* File handle of video file */
    VMINT is_seekable;           /* Seekable or not */
    VMUINT8 aud_channel_no;              /* Channel number of audio  */
    VMUINT16 aud_sample_rate;            /* Sample rate of audio  */

    VMINT is_drm_streaming;      /* DRM protection or not */
    VMUINT drm_handle;                 /* Handle of DRM protection file */

    VMWCHAR title_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];       /* Title descripton  */
    VMWCHAR artist_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];      /* Artist descripton  */
    VMWCHAR album_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];       /* Album descripton  */
    VMWCHAR author_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];      /* Author descripton  */
    VMWCHAR copyright_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];   /* copyright descripton  */
    VMWCHAR date_desc[VM_VIDEO_MAX_CONTENT_INFO_LEN+1];        /* Date  */
} vm_video_info_struct;





 /**
 *	This type of function is invoked when video file is open by vm_video_open_file and a result is returned or error happens.
 *	@param ret			result: >=0: success, <0 failed.
 *    @param video_info			Video info struct, whose value will be assigned after the video file is opened successfully.
 *	@return 			
 */
typedef void (*vm_video_open_result_callback)(VMINT ret, vm_video_info_struct *video_info);


  /**
 *	This type of function is invoked when video file is open by vm_video_play and the playing finishs or error happens.
 *	@param ret			result: >=0: success, <0 failed.
 *	@return 			
 */
typedef void (*vm_video_finish_callback) (VMINT ret);



 /**
 *	Open video file
 *	@param filename			Full path and file name.
 *    @param open_result_callback	Callback function.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *  		VM_VIDEO_ERR_DRM_PROHIBITED : DRM is prohibited.
 *  		VM_VIDEO_ERR_MEMORY_INSUFFICIENT : Memory is insufficient.
 *  		VM_VIDEO_ERR_FILE_TOO_LARGE : File size is too large.
 *  		VM_VIDEO_ERR_FRAMERATE_TOO_HIGH : Frame rate is to high.
 *		VM_VIDEO_ERR_INVALID_RESOULTION: Invalid resolution. 
 *  		VM_VIDEO_ERR_OPEN_FILE_FAILED : Failed for other reasons.
 */
 VMINT vm_video_open_file(
                    const VMWSTR filename,
                    vm_video_open_result_callback open_result_callback);


 /**
 *	Close video file.	
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *  		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_close_file(void);


 /**
 *	Open video using specified buffer data.
 *    @param buffer	Pointer to video buffer data.
 *    @param buffer_len	Length of buffer.
 *    @param info		Video info struct to be obtained.
 *	@return 			
 *  		VM_VIDEO_SUCCEED : Success.
 *  		VM_VIDEO_ERR_MEMORY_INSUFFICIENT : Memory is insufficient.
 *  		VM_VIDEO_ERR_FRAMERATE_TOO_HIGH : Frame rate is to high.
 *  		VM_VIDEO_ERR_OPEN_FILE_FAILED : Open file failed.
 */
  VMINT vm_video_open_buffer(
                    const VMUSTR buffer,
                    const VMUINT buffer_len,
                    vm_video_info_struct *info);
 
                    
 /**
 *	Close video buffer data, corresponding to vm_video_open_buffer.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *  		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_close_buffer(void);


 /**
 *	Play video(support 3gp/mp4 according to the feature of platform), there should be seek operation before playing.
 *    @param player_layer_handle		Handle of playing layer.
  *   @param base_layer_handle		Handle of background/foreground layer.
 *    @param repeat_count			Count of repeat times, 0 indicates recycle.
 *    @param is_play_audio			Is play audio(TRUE/FALSE).
 *    @param audio_path			Audio path(use the definition in vmmm.h, etc. VM_DEVICE_SPEAKER2).
 *    @param play_finish_callback		Callback function.
 *	@return 			
 *  		VM_VIDEO_SUCCEED : Success.
 *  		VM_VIDEO_ERR_DRM_PROHIBITED : DRM is prohibited.
 *  		VM_VIDEO_PROGRESSIVE_FILE_NOT_ENOUGH : Data not enough for playing.
 *  		VM_VIDEO_ERR_PLAY_FAILED : Play failed.
 */
 VMINT vm_video_play(
                    VMUINT player_layer_handle,
                    VMUINT base_layer_handle,
                    VMUINT16 repeat_count, 
                    VMINT is_play_audio,
                    VMINT audio_path, 
                    vm_video_finish_callback play_finish_callback);


/**
 *	 Stop playing.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_stop(void);


 /**
 *	Pause playing.
 *	@return
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
VMINT vm_video_pause(void);


 /**
 *	  Resume playing.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
VMINT vm_video_resume(void);


 /**
 *	Seek and get the frame of specified frame(Need to flush the screen to display).
 *    @param time		Time (ms).
 *    @param player_layer_handle		Handle of playing layer.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_seek_and_getframe(VMUINT64 time, VMUINT player_layer_handle);


 /**
 *	Snapshot and save to specified file in format of JPEG(Available only in phone with hardware decoder, 
 *  VM_VIDEO_ERR_SNAPSHOT_FAILED will be returned in phone with software decoder).
 *    @param player_layer_handle		Handle of playing layer
 *    @param file_name			File name to save(UCS2).
 *	@return 			
 *  		VM_VIDEO_SUCCEED : Success.
 *  		VM_VIDEO_ERR_SNAPSHOT_DISK_FULL : Snapshot failed because the disk is full.
 *  		VM_VIDEO_ERR_SNAPSHOT_WRITE_PROTECTION : Snapshot failed because of write protection.
 * 		VM_VIDEO_ERR_SNAPSHOT_FAILED : Snapshot failed.
 */
 VMINT vm_video_snapshot(VMUINT player_layer_handle, VMWSTR file_name);



 /**
 *	Set the brightness. Close will not save. It can be operated only in opened state,
 *  the value set during playing is going to take effect in the next time of playing.
 *	Available only in phone with hardware decoder, VM_VIDEO_FAILED 
 *  will be returned in phone with software decoder.
 *    @param brightness			Brightness(etc. VM_VIDEO_BRIGHTNESS_0)
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_set_brightness(VMUINT16 brightness);


 /**
 *	Set the brightness. Close will not save. It can be operated only in opened state,
 *  the value set during playing is going to take effect in the next time of playing.
 *	Available only in phone with hardware decoder, VM_VIDEO_FAILED 
 *  will be returned in phone with software decoder.
 *    @param contrast			Contrast(etc. VM_VIDEO_CONTRAST_0)
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_set_contrast(VMUINT16 contrast);



 /**
 *	 Get current play time.
 *    @param cur_play_time			Current play time to be obtained.
 *	@return 			
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
 VMINT vm_video_get_cur_play_time(VMUINT64 *cur_play_time); 


 /**
 *	Open stream media video according to URL(Will switch the calling VREAPP into background, 
 *  a new screen invoking video player of MTK will be opened and display).
 *    @param url			URL of video to be opened.
 *
 *	@return
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
VMINT vm_video_play_stream_from_rtsp_link(VMSTR url);
	
/**
 *	Open steam media video in sdp format(Will switch the calling VREAPP into background, 
 *  a new screen invoking video player of MTK will be opened and display).
 *    @param filename		File in sdp format to be opened.
 *	@param is_short		Is short file name in 8.3 format. TURE means yes, FALSE means no.
 *
 *	@return
 *  		VM_VIDEO_SUCCESS : Success.
 *		VM_VIDEO_FAILED : Failed.
 */
VMINT vm_video_play_stream_from_sdp_file(VMSTR filename, VMUCHAR is_short);

#ifdef __cplusplus
}
#endif

#endif
